<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ日志存储系统详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-overlay {
            background: linear-gradient(135deg, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.3) 100%);
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0,0,0,0.1);
        }
        .feature-icon {
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
        }
        .first-letter::first-letter {
            font-size: 3em;
            font-weight: bold;
            float: left;
            line-height: 0.8;
            margin-right: 8px;
            color: #4f46e5;
        }
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            width: 2px;
            height: 100%;
            background: #4f46e5;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <div class="relative h-96 md:h-screen/2 flex items-center justify-center bg-gray-900 overflow-hidden">
        <div class="absolute inset-0 hero-overlay z-10"></div>
        <div class="absolute inset-0">
            <img src="https://images.unsplash.com/photo-1517430816045-df4b7de11d1d?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2071&q=80" 
                 alt="Server Room" class="w-full h-full object-cover">
        </div>
        <div class="relative z-20 px-4 text-center max-w-4xl mx-auto">
            <h1 class="text-4xl md:text-6xl font-bold text-white mb-4">RocketMQ 日志存储系统解析</h1>
            <p class="text-xl md:text-2xl text-gray-200 mb-8">揭秘高性能消息队列的核心存储架构与优化策略</p>
            <div class="flex justify-center space-x-4">
                <a href="#file-organization" class="px-6 py-3 bg-indigo-600 hover:bg-indigo-700 text-white font-medium rounded-lg transition duration-300">
                    文件组织 <i class="fas fa-folder-tree ml-2"></i>
                </a>
                <a href="#cleanup-strategy" class="px-6 py-3 bg-gray-800 hover:bg-gray-700 text-white font-medium rounded-lg transition duration-300">
                    清理策略 <i class="fas fa-broom ml-2"></i>
                </a>
                <a href="#optimization" class="px-6 py-3 bg-gray-800 hover:bg-gray-700 text-white font-medium rounded-lg transition duration-300">
                    性能优化 <i class="fas fa-tachometer-alt ml-2"></i>
                </a>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-4 py-16 max-w-6xl">
        <!-- File Organization Section -->
        <section id="file-organization" class="mb-20">
            <div class="flex items-center mb-12">
                <div class="feature-icon bg-indigo-100 text-indigo-600 mr-4">
                    <i class="fas fa-folder-open text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">日志文件组织方式</h2>
            </div>
            <div class="first-letter text-gray-700 mb-8">
                RocketMQ的日志存储系统是其高性能和可靠性的基础，它采用了精心设计的文件组织方式，确保消息的高效存储和快速检索。通过分层、分片的存储架构，RocketMQ能够在高并发场景下保持稳定的性能表现。
            </div>

            <!-- File System Structure -->
            <div class="mb-12">
                <h3 class="text-2xl font-semibold text-gray-800 mb-6 border-b pb-2">日志文件体系</h3>
                
                <div class="grid md:grid-cols-2 gap-6 mb-10">
                    <!-- CommitLog Card -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                        <div class="p-6">
                            <div class="flex items-center mb-4">
                                <div class="w-10 h-10 bg-indigo-100 text-indigo-600 rounded-lg flex items-center justify-center mr-4">
                                    <i class="fas fa-file-alt"></i>
                                </div>
                                <h4 class="text-xl font-semibold">CommitLog</h4>
                            </div>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                    <span>主要的消息存储文件，所有消息按照写入顺序存储</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                    <span>物理存储路径：$HOME/store/commitlog/</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                    <span>文件命名规则：按照文件起始偏移量命名</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                    <span>默认单个文件大小：1GB</span>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <!-- ConsumeQueue Card -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                        <div class="p-6">
                            <div class="flex items-center mb-4">
                                <div class="w-10 h-10 bg-blue-100 text-blue-600 rounded-lg flex items-center justify-center mr-4">
                                    <i class="fas fa-list-ul"></i>
                                </div>
                                <h4 class="text-xl font-semibold">ConsumeQueue</h4>
                            </div>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                    <span>消息的逻辑队列，作为CommitLog的索引</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                    <span>物理存储路径：$HOME/store/consumequeue/{topic}/{queueId}/</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                    <span>默认单个文件大小：约6.4MB（存储30万个条目）</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                    <span>文件格式：固定长度条目，每个条目20字节</span>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <!-- IndexFile Card -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                        <div class="p-6">
                            <div class="flex items-center mb-4">
                                <div class="w-10 h-10 bg-green-100 text-green-600 rounded-lg flex items-center justify-center mr-4">
                                    <i class="fas fa-search"></i>
                                </div>
                                <h4 class="text-xl font-semibold">IndexFile</h4>
                            </div>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>提供基于消息Key的索引</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>物理存储路径：$HOME/store/index/</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>默认单个文件大小：约400MB</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>文件格式：哈希索引，包含哈希槽和索引条目</span>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <!-- Config Files Card -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover transition duration-300">
                        <div class="p-6">
                            <div class="flex items-center mb-4">
                                <div class="w-10 h-10 bg-purple-100 text-purple-600 rounded-lg flex items-center justify-center mr-4">
                                    <i class="fas fa-cog"></i>
                                </div>
                                <h4 class="text-xl font-semibold">配置文件</h4>
                            </div>
                            <ul class="space-y-2 text-gray-600">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                    <span>存储Broker的配置信息</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                    <span>物理存储路径：$HOME/store/config/</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                    <span>主要文件：topics.json、subscriptionGroup.json等</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                    <span>文件格式：JSON格式，便于读写和修改</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- Mermaid Diagram -->
                <div class="bg-white p-6 rounded-xl shadow-md mb-10">
                    <h4 class="text-xl font-semibold mb-4 text-gray-800">RocketMQ文件结构关系图</h4>
                    <div class="mermaid">
                        flowchart TD
                            A[Producer] -->|发送消息| B[CommitLog]
                            B -->|索引| C[ConsumeQueue]
                            B -->|索引| D[IndexFile]
                            E[Consumer] -->|消费消息| C
                            E -->|按Key查询| D
                            F[Broker配置] -->|配置信息| G[Config Files]
                            G -->|运行时参数| B
                            G -->|队列配置| C
                            G -->|索引配置| D
                    </div>
                </div>

                <!-- File Organization Principles -->
                <div class="bg-white p-8 rounded-xl shadow-md">
                    <h4 class="text-xl font-semibold mb-4 text-gray-800">文件组织结构原则</h4>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <h5 class="font-semibold text-indigo-600 mb-2 flex items-center">
                                <i class="fas fa-layer-group mr-2"></i> 分层存储
                            </h5>
                            <p class="text-gray-600">
                                按照功能划分不同类型的文件，每种文件类型有独立的存储目录，便于管理和维护。消息内容、索引和配置信息分开存储，各司其职。
                            </p>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <h5 class="font-semibold text-blue-600 mb-2 flex items-center">
                                <i class="fas fa-puzzle-piece mr-2"></i> 分片存储
                            </h5>
                            <p class="text-gray-600">
                                CommitLog按照固定大小分片，ConsumeQueue按照Topic和队列ID分片，IndexFile按照时间周期分片。这种设计提高了并行处理能力和系统扩展性。
                            </p>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <h5 class="font-semibold text-green-600 mb-2 flex items-center">
                                <i class="fas fa-object-group mr-2"></i> 元数据与数据分离
                            </h5>
                            <p class="text-gray-600">
                                消息内容存储在CommitLog中，消息索引存储在ConsumeQueue和IndexFile中，配置信息存储在配置文件中。这种分离设计提高了系统效率和可靠性。
                            </p>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <h5 class="font-semibold text-purple-600 mb-2 flex items-center">
                                <i class="fas fa-tags mr-2"></i> 文件命名规则
                            </h5>
                            <p class="text-gray-600">
                                使用数字命名，便于排序和查找；文件名反映文件的起始偏移量或创建时间，便于快速定位特定消息，简化了文件管理逻辑。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Log Cleanup Section -->
        <section id="cleanup-strategy" class="mb-20">
            <div class="flex items-center mb-12">
                <div class="feature-icon bg-red-100 text-red-600 mr-4">
                    <i class="fas fa-trash-alt text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">日志清理和压缩策略</h2>
            </div>
            <div class="first-letter text-gray-700 mb-8">
                RocketMQ采用了多种策略来管理日志文件的生命周期，确保存储空间的有效利用和系统性能的稳定。通过智能的清理机制和压缩技术，在保证数据可靠性的同时最大化存储效率。
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <!-- Retention Mechanisms -->
                <div class="bg-white p-6 rounded-xl shadow-md">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-calendar-times text-red-500 mr-2"></i> 日志保留机制
                    </h3>
                    <div class="space-y-4">
                        <div class="p-4 bg-red-50 rounded-lg">
                            <h4 class="font-medium text-red-700 mb-2">基于时间的保留策略</h4>
                            <p class="text-gray-600 text-sm">
                                默认保留时间72小时（可配置），超过保留时间的文件会被自动删除，通过fileReservedTime参数配置。
                            </p>
                        </div>
                        <div class="p-4 bg-orange-50 rounded-lg">
                            <h4 class="font-medium text-orange-700 mb-2">基于磁盘空间的保留策略</h4>
                            <p class="text-gray-600 text-sm">
                                当磁盘使用率超过阈值时触发清理，默认阈值75%（可配置），通过diskMaxUsedSpaceRatio参数配置。
                            </p>
                        </div>
                        <div class="p-4 bg-yellow-50 rounded-lg">
                            <h4 class="font-medium text-yellow-700 mb-2">基于文件数量的保留策略</h4>
                            <p class="text-gray-600 text-sm">
                                限制每种类型文件的最大数量，超过数量限制时删除最旧的文件，通过相关参数配置。
                            </p>
                        </div>
                    </div>
                </div>

                <!-- Cleanup Process -->
                <div class="bg-white p-6 rounded-xl shadow-md">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-broom text-indigo-500 mr-2"></i> 日志清理流程
                    </h3>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                                <i class="fas fa-clock"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">定时检查</h4>
                                <p class="text-gray-600 text-sm">
                                    后台线程每10秒检查一次文件状态，可通过cleanResourceInterval参数调整检查频率。
                                </p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                                <i class="fas fa-check-circle"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">清理条件判断</h4>
                                <p class="text-gray-600 text-sm">
                                    检查文件的最后修改时间、当前磁盘使用率和文件是否仍被引用，综合判断是否需要清理。
                                </p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                                <i class="fas fa-trash-restore"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">安全删除</h4>
                                <p class="text-gray-600 text-sm">
                                    确保文件不再被任何消费者引用，先将文件重命名再删除，避免删除正在使用的文件。
                                </p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                                <i class="fas fa-exclamation-triangle"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">强制删除</h4>
                                <p class="text-gray-600 text-sm">
                                    当磁盘空间紧张时触发强制删除，优先删除最旧的文件，可能导致部分历史消息不可访问。
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Compression Strategies -->
            <div class="bg-white p-8 rounded-xl shadow-md">
                <h3 class="text-xl font-semibold mb-6 text-gray-800 flex items-center">
                    <i class="fas fa-compress-arrows-alt text-blue-500 mr-2"></i> 日志压缩策略
                </h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="font-medium text-blue-700 mb-3 flex items-center">
                            <i class="fas fa-file-archive mr-2"></i> 消息压缩
                        </h4>
                        <p class="text-gray-600 mb-4">
                            支持对消息体进行压缩存储，默认不启用，可通过配置开启。支持多种压缩算法，如LZ4、Snappy等，有效减少存储空间占用。
                        </p>
                        <div class="bg-blue-50 p-3 rounded-lg">
                            <div class="flex items-center text-sm">
                                <span class="font-medium text-blue-700 w-24">LZ4</span>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div class="bg-blue-600 h-2.5 rounded-full" style="width: 70%"></div>
                                </div>
                                <span class="ml-2 text-blue-700">高速度</span>
                            </div>
                            <div class="flex items-center text-sm mt-2">
                                <span class="font-medium text-blue-700 w-24">Snappy</span>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div class="bg-blue-600 h-2.5 rounded-full" style="width: 65%"></div>
                                </div>
                                <span class="ml-2 text-blue-700">平衡</span>
                            </div>
                        </div>
                    </div>
                    <div>
                        <h4 class="font-medium text-purple-700 mb-3 flex items-center">
                            <i class="fas fa-database mr-2"></i> 索引压缩
                        </h4>
                        <p class="text-gray-600 mb-4">
                            ConsumeQueue采用固定长度格式，不进行压缩；IndexFile采用哈希索引，空间利用率较高，不需要额外压缩。
                        </p>
                        <div class="flex items-center space-x-4">
                            <div class="text-center">
                                <div class="w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-2">
                                    <i class="fas fa-list-ol text-purple-600 text-2xl"></i>
                                </div>
                                <span class="text-sm font-medium text-purple-700">固定长度</span>
                            </div>
                            <div class="text-center">
                                <div class="w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-2">
                                    <i class="fas fa-hashtag text-purple-600 text-2xl"></i>
                                </div>
                                <span class="text-sm font-medium text-purple-700">哈希索引</span>
                            </div>
                        </div>
                    </div>
                    <div>
                        <h4 class="font-medium text-green-700 mb-3 flex items-center">
                            <i class="fas fa-plus-circle mr-2"></i> 增量存储
                        </h4>
                        <p class="text-gray-600">
                            配置文件采用增量更新方式，只记录变更的部分，减少存储空间。这种设计特别适合频繁更新的配置信息，降低了I/O开销。
                        </p>
                    </div>
                    <div>
                        <h4 class="font-medium text-red-700 mb-3 flex items-center">
                            <i class="fas fa-file-export mr-2"></i> 文件合并
                        </h4>
                        <p class="text-gray-600">
                            目前RocketMQ不支持日志文件的合并，每个文件大小固定，不会动态调整。这种设计简化了文件管理，但可能影响空间利用率。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Optimization Section -->
        <section id="optimization">
            <div class="flex items-center mb-12">
                <div class="feature-icon bg-yellow-100 text-yellow-600 mr-4">
                    <i class="fas fa-tachometer-alt text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">日志存储性能优化方法</h2>
            </div>
            <div class="first-letter text-gray-700 mb-8">
                RocketMQ提供了多种优化方法，以提高日志存储的性能和可靠性，满足不同场景的需求。从硬件配置到系统参数调优，全方位的优化手段可以帮助您构建高性能的消息队列系统。
            </div>

            <!-- Optimization Tabs -->
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12">
                <div class="border-b border-gray-200">
                    <nav class="flex -mb-px">
                        <button class="optimization-tab active py-4 px-6 text-center border-b-2 font-medium text-sm border-indigo-500 text-indigo-600">
                            <i class="fas fa-microchip mr-2"></i> 硬件层面
                        </button>
                        <button class="optimization-tab py-4 px-6 text-center border-b-2 font-medium text-sm border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300">
                            <i class="fas fa-sliders-h mr-2"></i> 系统参数
                        </button>
                        <button class="optimization-tab py-4 px-6 text-center border-b-2 font-medium text-sm border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300">
                            <i class="fas fa-project-diagram mr-2"></i> 存储结构
                        </button>
                        <button class="optimization-tab py-4 px-6 text-center border-b-2 font-medium text-sm border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300">
                            <i class="fas fa-running mr-2"></i> 运行时
                        </button>
                    </nav>
                </div>
                <div class="p-6">
                    <!-- Hardware Optimization -->
                    <div class="optimization-content active">
                        <div class="grid md:grid-cols-3 gap-6">
                            <div class="bg-gray-50 p-5 rounded-lg">
                                <div class="flex items-center mb-3">
                                    <div class="w-10 h-10 bg-indigo-100 text-indigo-600 rounded-full flex items-center justify-center mr-3">
                                        <i class="fas fa-hdd"></i>
                                    </div>
                                    <h4 class="font-semibold">存储介质选择</h4>
                                </div>
                                <ul class="text-gray-600 space-y-2">
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                                        <span>使用SSD存储CommitLog，提高随机读写性能</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                                        <span>使用大容量HDD存储历史数据</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                                        <span>考虑使用RAID提高可靠性和性能</span>
                                    </li>
                                </ul>
                            </div>
                            <div class="bg-gray-50 p-5 rounded-lg">
                                <div class="flex items-center mb-3">
                                    <div class="w-10 h-10 bg-blue-100 text-blue-600 rounded-full flex items-center justify-center mr-3">
                                        <i class="fas fa-memory"></i>
                                    </div>
                                    <h4 class="font-semibold">内存配置</h4>
                                </div>
                                <ul class="text-gray-600 space-y-2">
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-blue-500 mt-1 mr-2 text-xs"></i>
                                        <span>增加系统内存，提高页缓存利用率</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-blue-500 mt-1 mr-2 text-xs"></i>
                                        <span>配置合适的JVM堆内存，避免频繁GC</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-blue-500 mt-1 mr-2 text-xs"></i>
                                        <span>推荐物理内存至少为4GB</span>
                                    </li>
                                </ul>
                            </div>
                            <div class="bg-gray-50 p-5 rounded-lg">
                                <div class="flex items-center mb-3">
                                    <div class="w-10 h-10 bg-green-100 text-green-600 rounded-full flex items-center justify-center mr-3">
                                        <i class="fas fa-network-wired"></i>
                                    </div>
                                    <h4 class="font-semibold">网络配置</h4>
                                </div>
                                <ul class="text-gray-600 space-y-2">
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-green-500 mt-1 mr-2 text-xs"></i>
                                        <span>使用高性能网卡，提高网络吞吐量</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-green-500 mt-1 mr-2 text-xs"></i>
                                        <span>调整网络参数，如TCP缓冲区大小</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check text-green-500 mt-1 mr-2 text-xs"></i>
                                        <span>考虑使用独立网络，避免与其他业务竞争</span>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- System Parameters Optimization -->
            <div class="bg-white p-8 rounded-xl shadow-md mb-12">
                <h3 class="text-xl font-semibold mb-6 text-gray-800">系统参数优化</h3>
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">参数类别</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">优化选项</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">影响</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">推荐配置</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">刷盘策略</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">flushDiskType</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800">性能 vs 可靠性</span>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">异步刷盘(ASYNC_FLUSH)用于高性能场景</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">复制策略</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">brokerRole</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">高可用性</span>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">SYNC_MASTER用于关键业务</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">文件预分配</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">mappedFileSizeCommitLog</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-purple-100 text-purple-800">I/O效率</span>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">1GB(默认)，可根据消息大小调整</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">页缓存利用</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">transientStorePoolEnable</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">内存使用</span>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">异步刷盘时建议开启</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <!-- Storage Structure Optimization -->
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <div class="bg-white p-6 rounded-xl shadow-md h-full">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">存储结构优化</h3>
                        <div class="space-y-5">
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2 flex items-center">
                                    <i class="fas fa-file-signature text-indigo-500 mr-2"></i> 文件大小设置
                                </h4>
                                <p class="text-gray-600 text-sm">
                                    合理设置CommitLog文件大小(默认1GB)，较大的文件减少文件数量但增加恢复时间，较小的文件增加管理开销但提高并行度。
                                </p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2 flex items-center">
                                    <i class="fas fa-search-plus text-blue-500 mr-2"></i> 索引优化
                                </h4>
                                <p class="text-gray-600 text-sm">
                                    调整IndexFile的哈希槽数量，平衡内存占用和查询性能；根据消息Key的分布特性优化哈希函数；评估是否需要开启索引功能。
                                </p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2 flex items-center">
                                    <i class="fas fa-columns text-green-500 mr-2"></i> 队列数量优化
                                </h4>
                                <p class="text-gray-600 text-sm">
                                    合理设置Topic的队列数量，提高并行度；队列数量过多增加资源消耗，过少限制并行处理能力；根据业务负载动态调整。
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="bg-white p-6 rounded-xl shadow-md h-full">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">运行时优化</h3>
                        <div class="space-y-5">
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2 flex items-center">
                                    <i class="fas fa-boxes text-purple-500 mr-2"></i> 批量处理
                                </h4>
                                <p class="text-gray-600 text-sm">
                                    启用消息批量发送和批量消费，减少I/O操作次数，提高吞吐量；通过相关参数配置批量大小，平衡延迟和吞吐量。
                                </p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2 flex items-center">
                                    <i class="fas fa-tasks text-yellow-500 mr-2"></i> 后台任务调度
                                </h4>
                                <p class="text-gray-600 text-sm">
                                    优化清理线程的执行频率，避免清理操作与高峰期重叠；通过相关参数配置后台任务的执行时间和频率。
                                </p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2 flex items-center">
                                    <i class="fas fa-fire text-red-500 mr-2"></i> 预热机制
                                </h4>
                                <p class="text-gray-600 text-sm">
                                    系统启动时预热页缓存，加载关键文件到内存，减少冷启动时的性能抖动；可通过脚本或工具实现自动化预热。
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Performance Monitoring -->
            <div class="bg-indigo-50 p-8 rounded-xl shadow-md border border-indigo-100">
                <h3 class="text-xl font-semibold mb-6 text-indigo-800">性能监控与持续优化</h3>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="bg-white p-5 rounded-lg shadow-sm">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-indigo-100 text-indigo-600 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-chart-line"></i>
                            </div>
                            <h4 class="font-semibold">实时监控</h4>
                        </div>
                        <p class="text-gray-600 text-sm">
                            部署监控系统实时跟踪存储性能指标，包括磁盘I/O、内存使用、网络吞吐量、消息堆积等关键指标，及时发现瓶颈。
                        </p>
                    </div>
                    <div class="bg-white p-5 rounded-lg shadow-sm">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-indigo-100 text-indigo-600 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-sliders-h"></i>
                            </div>
                            <h4 class="font-semibold">动态调整</h4>
                        </div>
                        <p class="text-gray-600 text-sm">
                            根据监控结果动态调整系统参数，如刷盘策略、内存分配、线程池大小等，适应业务负载变化，保持最佳性能状态。
                        </p>
                    </div>
                    <div class="bg-white p-5 rounded-lg shadow-sm">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-indigo-100 text-indigo-600 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-search-dollar"></i>
                            </div>
                            <h4 class="font-semibold">定期评估</h4>
                        </div>
                        <p class="text-gray-600 text-sm">
                            定期进行全面的性能评估和优化，分析历史数据趋势，预测未来需求，提前规划容量和性能扩展方案。
                        </p>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto px-4 max-w-6xl">
            <div class="text-center">
                <h3 class="text-xl font-semibold text-white mb-2">技术小馆</h3>
                <p class="mb-4">探索技术奥秘，分享实践真知</p>
                <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-300">
                    <i class="fas fa-globe mr-1"></i> http://www.yuque.com/jtostring
                </a>
            </div>
            <div class="mt-8 pt-8 border-t border-gray-800 text-center text-sm text-gray-500">
                © 2023 技术小馆. All rights reserved.
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });

        // Tab functionality
        document.addEventListener('DOMContentLoaded', function() {
            const tabs = document.querySelectorAll('.optimization-tab');
            const contents = document.querySelectorAll('.optimization-content');
            
            tabs.forEach(tab => {
                tab.addEventListener('click', function() {
                    // Remove active class from all tabs and contents
                    tabs.forEach(t => t.classList.remove('active', 'border-indigo-500', 'text-indigo-600'));
                    tabs.forEach(t => t.classList.add('border-transparent', 'text-gray-500'));
                    contents.forEach(c => c.classList.remove('active'));
                    
                    // Add active class to clicked tab and corresponding content
                    this.classList.add('active', 'border-indigo-500', 'text-indigo-600');
                    this.classList.remove('border-transparent', 'text-gray-500');
                    
                    const tabIndex = Array.from(tabs).indexOf(this);
                    contents[tabIndex].classList.add('active');
                });
            });
            
            // Smooth scrolling for anchor links
            document.querySelectorAll('a[href^="#"]').forEach(anchor => {
                anchor.addEventListener('click', function (e) {
                    e.preventDefault();
                    document.querySelector(this.getAttribute('href')).scrollIntoView({
                        behavior: 'smooth'
                    });
                });
            });
        });
    </script>
</body>
</html>